const flyConfig = require('../configs/flyConfig');
module.exports = class {
    constructor() {
        this.fly = null;
        this.flyPrefab = null;
        this.init();
    }

    init() {
        this.flyLayer = cc.find('Canvas/layerGame/gameLayerFly');
    }

    loadFlyRes() {
        ICPC.addOneLoad();
        cc.loader.loadRes(flyConfig.flyPrefabPath, cc.Prefab, (error, resource) => {
            if (error) {
                throw error;
            }
            if (!(resource instanceof cc.Prefab)) {
                console.error('#18 Prefab error', flyConfig.flyPrefabPath);
                return;
            }
            this.flyPrefab = resource;
            ICPC.emit('loadFlyResEnd');
            ICPC.oneLoadOver();
        });
    }

    setFly() {
        if (this.fly == null) {
            this.fly = cc.instantiate(this.flyPrefab);
            this.fly.getComponent('fly').setIcon(1);
            this.flyLayer.addChild(this.fly);
        }
        //
        this.fly.x = 0;
        this.fly.active = true;
    }

    clearFly() {
        this.fly.active = false;
    }

    getFlyNode() {
        return this.fly;
    }
}